package cn.harry.wx.entity;

import cn.hutool.core.date.DatePattern;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;

import java.io.Serializable;
import java.util.Date;

/**
 * 消息模板
 *
 * @author honghh
 * Date 2021-04-08 16:19:27
 * Copyright (C) www.tech-harry.cn
 */
@Data
@TableName("wx_msg_template")
public class WxMsgTemplate implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId
    @ApiModelProperty(value = "主键")
    private Long id;

    /**
     * appid
     */
    @ApiModelProperty(value = "appid")
    private String appid;
    /**
     * 公众号模板ID
     */
    @ApiModelProperty(value = "公众号模板ID")
    private String templateId;
    /**
     * 模版名称
     */
    @ApiModelProperty(value = "模版名称")
    @TableField(value = "`name`")
    private String name;
    /**
     * 标题
     */
    @ApiModelProperty(value = "标题")
    private String title;
    /**
     * 模板内容
     */
    @ApiModelProperty(value = "模板内容")
    private String content;
    /**
     * 消息内容
     */
    @ApiModelProperty(value = "消息内容")
    private JSONArray data;
    /**
     * 链接
     */
    @ApiModelProperty(value = "链接")
    private String url;
    /**
     * 小程序信息
     */
    @ApiModelProperty(value = "小程序信息")
    private JSONObject miniprogram;
    /**
     * 是否有效
     */
    @ApiModelProperty(value = "是否有效")
    @TableField(value = "`status`", whereStrategy = FieldStrategy.NEVER)
    private boolean status;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    /**
     * 修改时间
     */
    @JsonFormat(pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
    @ApiModelProperty(value = "修改时间")
    private Date modifyTime;
    /**
     * 有效状态：0->无效；1->有效
     */
    @TableLogic
    @ApiModelProperty(value = "有效状态：0->无效；1->有效")
    private Integer valid;
    /**
     * 开始时间
     */
    @JsonIgnore
    @TableField(exist = false)
    private String beginTime;

    /**
     * 结束时间
     */
    @JsonIgnore
    @TableField(exist = false)
    private String endTime;

    public WxMsgTemplate() {

    }

    public WxMsgTemplate(WxMpTemplate mpTemplate, String appid) {
        this.appid = appid;
        this.templateId = mpTemplate.getTemplateId();
        this.title = mpTemplate.getTitle();
        this.name = mpTemplate.getTemplateId();
        this.content = mpTemplate.getContent();
        this.status = true;
    }
}
